package com.hllxd.hism.star.basic.service.controller2;

import com.hllxd.hism.framework.httprpc.service.*;
import com.hllxd.hism.star.basic.service.exception.BusinessException;
import com.hllxd.hism.star.basic.service.service.DetailService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * web明细数据
 */
@Slf4j
@RestGrpcService
@RestGrpcMapping("/v1/detail")
public class DetailController2 {

    @Autowired
    private DetailService detailService;

    @Data
    public static class Param {
        private String startTime;
        private String endTime;
    }

    /**
     * 点击明细查询
     */
    @RestGrpcMapping("/listClickDetail.do")
    public NTSTATUS listClickDetail(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            Param aa = params.driverObject(Param.class);
            result.setData(detailService.listClickDetail(aa.getStartTime(), aa.getEndTime()));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

    /**
     * 曝光明细查询
     */
    @RestGrpcMapping("/listExposureDetail.do")
    public NTSTATUS listExposureDetail(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            Param aa = params.driverObject(Param.class);
            result.setData(detailService.listExposureDetail(aa.getStartTime(), aa.getEndTime()));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

    /**
     * 投递明细查询
     */
    @RestGrpcMapping("/listResumedeliveryDetail.do")
    public NTSTATUS listResumedeliveryDetail(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            Param aa = params.driverObject(Param.class);
            result.setData(detailService.listResumedeliveryDetail(aa.getStartTime(), aa.getEndTime()));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

    /**
     * 计费明细查询
     */
    @RestGrpcMapping("/listBillingDetail.do")
    public NTSTATUS listBillingDetail(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            Param aa = params.driverObject(Param.class);
            result.setData(detailService.listBillingDetail(aa.getStartTime(), aa.getEndTime()));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

    /**
     * ImOpen
     */
    @RestGrpcMapping("/listImOpenDetail.do")
    public NTSTATUS listImOpenDetail(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            Param aa = params.driverObject(Param.class);
            result.setData(detailService.listImOpenDetail(aa.getStartTime(), aa.getEndTime()));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

    /**
     * 微聊邀请
     */
    @RestGrpcMapping("/listIminviteDetail.do")
    public NTSTATUS listIminviteDetail(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            Param aa = params.driverObject(Param.class);
            result.setData(detailService.listIminviteDetail(aa.getStartTime(), aa.getEndTime()));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

    /**
     * 职位发布
     */
    @RestGrpcMapping("/listJobPublishDetail.do")
    public NTSTATUS listJobPublishDetail(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            Param aa = params.driverObject(Param.class);
            result.setData(detailService.listJobPublishDetail(aa.getStartTime(), aa.getEndTime()));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

    /**
     * 电话b2c
     */
    @RestGrpcMapping("/listB2cBillDetail.do")
    public NTSTATUS listB2cBillDetail(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            Param aa = params.driverObject(Param.class);
            result.setData(detailService.listB2cBillDetail(aa.getStartTime(), aa.getEndTime()));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

    /**
     * 电话c2b
     */
    @RestGrpcMapping("/listAxbbillInfoDetail.do")
    public NTSTATUS listAxbbillInfoDetail(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            Param aa = params.driverObject(Param.class);
            result.setData(detailService.listAxbbillInfoDetail(aa.getStartTime(), aa.getEndTime()));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

}
